<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vuejs实现计数器</title>
    <link rel="stylesheet" href="./css/index.css">
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>
    <div class="input-num">
        <button @click="sub">-</button>
        <span>{{num}}</span>
        <button @click="add">+</button>

    </div>
    <script>
        var app = new Vue({
            el: '.input-num',
            data: {
                num: 1
            },
            methods: {
                sub: function() {
                    if (this.num > 0) {
                        this.num -= 1;
                    }
                },
                add: function() {
                    if (this.num < 10) {
                        this.num += 1;
                    }
                }
            }
        })
    </script>
</body>

</html>